package com.rhyton.component.upload.web;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;

import com.opensymphony.xwork.ActionSupport;
import com.rhyton.component.upload.domain.AttactFile;
import com.rhyton.component.upload.service.AttactFileManager;

public class FileDownloadAction extends ActionSupport {

    private static final long serialVersionUID = -6801542069804847898L;

    private InputStream fileStream;

    private AttactFile attactFile;
    
    public String execute() throws FileNotFoundException {
	AttactFile file = getAttactFileManager().getAttachFile(attactFile.getId());
	if(file!=null){    
	    this.setAttactFile(file);
	    this.fileStream = new FileInputStream(this.getAttactFile().getFile());
	    return SUCCESS;
	}else{
	    return ActionSupport.ERROR;
	}
	
    }

    private AttactFileManager attactFileManager;

    public AttactFileManager getAttactFileManager() {
	return attactFileManager;
    }

    public void setAttactFileManager(AttactFileManager downloadFileMgr) {
	this.attactFileManager = downloadFileMgr;
    }

    public AttactFile getAttactFile() {
	return attactFile;
    }

    public void setAttactFile(AttactFile attactFile) {
	this.attactFile = attactFile;
    }

    public InputStream getFileStream() {
	return fileStream;
    }
}
